
  
 var getGoodsList = 'get_goods_list';
 var supplierID;   // 商品 id
 var catID;       //  商品分类id
 var priceSort; // =   'desc'; //价格排序(小写)  asc升序 desc降序 
var page = 1;
  
  
  mui.init({
            swipeBack: false,
           
           pullRefresh:{
           	   container: '#scroll01',
           	   down:{
           	   	  contentdown : "下拉可以刷新",//可选，在下拉可刷新状态时，下拉刷新控件上显示的标题内容
                  contentover : "释放立即刷新",//可选，在释放可刷新状态时，下拉刷新控件上显示的标题内容
                  contentrefresh : "正在刷新...",//可选，正在刷新状态时，下拉刷新控件上显示的标题内容
           	   	  callback:pulldownRefresh,
           	   },
           	   up: {
           	   	  contentrefresh:'正在加载中...',
           	   	  callback:pullupRefresh,
           	   }
           }
           
 });
 
    //  获取上个页面数据
    mui.plusReady(function() {
   	       var  self  = plus.webview.currentWebview();
   	        supplierID = self.supplier_id;
   });
 
 
      
      (function($) {
            $('.mui-scroll-wrapper').scroll({
                indicators: true //是否显示滚动条
            });

          //  var html2 = "<iframe src='../html/.ye-shop-derails2.html' width='100%'  height='100%' scrolling='no' frameborder='0'></iframe>";
            var item2 = document.getElementById('item2mobile');

            document.getElementById('slider').addEventListener('slide', function(e) {
                if (e.detail.slideNumber === 1) {
                    if (item2.querySelector('.mui-loading')) {
                        setTimeout(function() {
                            item2.querySelector('.mui-scroll').innerHTML = html2;
                        }, 500);
                    }
                } else if (e.detail.slideNumber === 2) {
                    if (item3.querySelector('.mui-loading')) {
                        setTimeout(function() {
                            item3.querySelector('.mui-scroll').innerHTML = html3;
                        }, 500);
                    }
                }
            });
        })(mui);



        /*  信息数据部分
         */
        var message = new Vue({
            el: '#yty-itemData',
            data: {
                items: [{
                    ytyText: '电话',
                    ytyDetails: 'ddd'
                }, {
                    ytyText: '地址  ',
                    ytyDetails: 'ddd'
                }, {
                    ytyText: '营业时间',
                    ytyDetails: 'xdfd'
                }, {
                    ytyText: '配送服务',
                    ytyDetails: 'xdfd'
                }, {
                    ytyText: '店铺信息',
                    ytyDetails: 'xdfd'
                }, {
                    ytyText: '暂无数据',
                    ytyDetails: ''
                }],
                ytydivs: []
            }
        });
        // 
        
        
        /* 滚动广告数据
          */
        var near = new Vue({
            el: '#yty-near',
            data: {
                items: [ //class="yty-h"
                    {
                        ytyclass: 'mui-slider-item mui-slider-item-duplicate yty-h',
                        ytyimg: '../images/yuantiao.jpg'
                    }, {
                        ytyclass: 'mui-slider-item yty-h',
                        ytyimg: '../images/shuijiao.jpg'
                    }, {
                        ytyclass: 'mui-slider-item yty-h',
                        ytyimg: '../images/muwu.jpg'
                    }, {
                        ytyclass: 'mui-slider-item yty-h',
                        ytyimg: '../images/cbd.jpg'
                    }, {
                        ytyclass: 'mui-slider-item yty-h',
                        ytyimg: '../images/yuantiao.jpg'
                    }, {
                        ytyclass: 'mui-slider-item mui-slider-item-duplicate yty-h',
                        ytyimg: '../images/shuijiao.jpg'
                    },
                ],
                ytydivs: [{
                    divclass: 'mui-indicator mui-active'
                }, {
                    divclass: 'mui-indicator'
                }, {
                    divclass: 'mui-indicator'
                }, {
                    divclass: 'mui-indicator'
                }, ]
            }
        });


        /* 商品列表数据
          */
        var cellData = new Vue({
        	el: '#scroll01',
        	data:{
        		cells:[
        		],
        	}
        	
        });

        /*
         *  筛选列表数据
         */
         var screenData = new Vue({
         	el:'#popover',
         	data: {
         		 scrDatas:[
         		 ],
         	},
         });
         
  // 筛选列表  
         	 mui.getJSON('http://www.xiaiyepu.cn/mobile/client_api.php',{
                                   act:'get_goods_category',
                                   supplier_id:31
	                         },function(data){
	                                  	//服务器返回响应，根据响应结果，分析是否登录成功；data.o[0]['cat_id']+'--------->'+screenData.scrDatas[0]['cat_id']
	                                  	        data.o.push({cat_id:'0',cat_name:'取消' });
		                                   	     screenData.scrDatas  =  data.o;
	                              },'json'
                        );
                        
              
     //http://www.xiaiyepu.cn/mobile/client_api.php?act=get_goods_list&supplier_id=31&cat_id=147&price_sort=asc                   
    // 根据 商城列表
//     mui.post('http://www.xiaiyepu.cn/mobile/client_api.php',{
//	                act:'get_supplier_list',
//     	            supplier_type:0
//	},function(data){
//		//服务器返回响应，根据响应结果，分析是否登录成功；
//		  cellData.cells = data.o;
//	},'json' );


     function getListData(count,catid,supplierid,pricesort,getgoodslist) {
	         	   mui.post('http://www.xiaiyepu.cn/mobile/client_api.php',{
       	            act:getgoodslist,
       	             supplier_id:supplierid, 
       	             cat_id:catid,  
       	             price_sort:pricesort, 
       	             page: count,
                   	},function(data){
		                   //服务器返回响应，根据响应结果，分析是否登录成功；
		
	               	if(data.c == 1) {
	               		  
	               		  console.log('-->'+data.o);
	               		if (data.o == null) {
	               			  return;
	               		}else {
	               			  return  cellData.cells = data.o;
	               		}
			             
	                	}else {
		                	return ;
		              }
		 
	            },'json' );  
	}
	
	getListData(page,catID,supplierID,null,'get_goods_list');
	
    
    /**
	 * 下拉刷新具体业务实现
	 */
   function pulldownRefresh() {
   	   page = 1;
   	    getListData(page,catID,supplierID,priceSort,'get_goods_list');
   	  console.log('------下啦'); 
           mui('#scroll01').pullRefresh().endPulldownToRefresh();
 	};
    
    
  
  	function pullupRefresh() {
  	   	/**
  	      *  上拉代码
  	      */
  	    setTimeout(function() {
        page++;
           var data =  getListData(page,catID,supplierID,'desc','get_goods_list');
            
            
           if(data != null) {
           	    cellData.cells.push(
	                data
	             );
           }

  	        mui('#scroll01').pullRefresh().endPullupToRefresh(true);

  	    }, 1000);

  	};
  	
  	
  	  var  i = 0; // 控制价格点击
  	  var  j = 0;
  	  var  script = '--';
  	  var  script2 = '--';
  	  var ytyAs = document.getElementById('yty-threeChoices').getElementsByTagName('a');
  	  var ytyPopoverImg = document.getElementById('openPopover');
       var ytyPriceImg  = document.getElementById('openPrice');
    /*三个选项*/
    mui('#yty-threeChoices').on('tap', 'a', function() {

       var title  = this.getAttribute('title'); 
       
           if (title == '综合'){
             page = 1;
              i = 0;
           	  j = 0;
           	  script = "--";
           	  script2 = '--';
           	   priceSort = null; 
           	   catID = null;
           	  ytyAs[2].className = 'mui-control-item ms-price ms-nav-icon';
           	   ytyAs[1].style.color = '';
           	  ytyAs[1].className = 'mui-control-item ms-price ms-nav-icon';
           	  ytyPopoverImg.src = '../images/ms_screen.png';
           	  ytyPriceImg.src  =   '../images/ms_dire.png';
 
              getListData(page,catID,supplierID,priceSort,'get_goods_list');
           }else {

           	    if(title == '价格') {
           	    	   i++;
                      script2 = '-+';
                      console.log(ytyAs[1].className+'======' +i);
  
                          ytyAs[1].className = 'mui-control-item ms-price ms-nav-icon mui-active';
                          
                          if(script  == "+-") {
                          	ytyAs[2].className = 'mui-control-item ms-price ms-nav-icon mui-active';
                          }
                          
                   
 
           	          if(i == 1){
           	          	    
           	          	     ytyPriceImg.src =   '../images/ms_dire_down.png';
           	          	     priceSort = 'desc'; 
           	          	     
           	          }else  {
           	          	      ytyPriceImg.src =   '../images/ms_dire_up.png';
           	          	      priceSort = 'asc'; 
                           i = 0;
           	          }
           	         getListData(page,catID,supplierID,priceSort,'get_goods_list');
                 }
           	         
                if(title == '筛选') {
                	  j++;
                     script = '+-';

                  ytyPopoverImg.src = '../images/ms_screen_act.png';
                  if(j == 1){
                   	     
                     	 ytyAs[2].className = 'mui-control-item ms-screen ms-nav-icon';
                     	 if(script2  == '-+'){
                     	 	console.log(ytyAs[1].className+'d==饿e的===='+ j);
                     
                                ytyAs[1].style.color = '#FF4777';
                     	// 	ytyAs[1].className = 'mui-control-item ms-screen ms-nav-icon mui-active';
                     	 }
                     	 
                  }else {
                  	 ytyAs[2].className = 'mui-control-item ms-screen ms-nav-icon';
                  	     j = 0;
                  }
                   
                    
                }
           }
 
    });
        
 

     mui('#popover').on('tap','a',function(){
     	  var ytyid =  this.getAttribute('title');
     
     	  if(ytyid == 0) {
     	  	    mui('#popover').popover('hide');
     	    	catID = null;
     	  	     ytyAs[2].className = 'mui-control-item ms-screen ms-nav-icon';
     	  	      ytyPopoverImg.src = '../images/ms_screen.png';
     	  	     
     	  }else {
     	  	      catID= ytyid;
     	  	      getListData(page,catID,supplierID,priceSort,'get_goods_list');
     	  }
     	   
     });

        /*
         *   滚动动画 一定要在数据部分前面
         */
        var slider = mui("#yty-near");
        slider.slider({
            interval: 5000
        });